<template>
  <div class="app-container">
    <el-table
      v-loading="loading"
      :data="list"
      element-loading-text="加载中"
      border
      fit
      highlight-current-row
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column align="center" label="ID" width="95" prop="id"></el-table-column>
      <el-table-column label="课程名" prop="course.name"></el-table-column>
      <el-table-column label="学年学期">
        <template v-slot="scope">
          <year-semester-show :year="scope.row.course.year" :semester="scope.row.course.semester"></year-semester-show>
        </template>
      </el-table-column>
      <el-table-column label="成绩" prop="score"></el-table-column>
<!--      <el-table-column label="获得学分" prop="credit"></el-table-column>-->
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="onClickCancel(scope.row.id)" v-show="scope.row.course.type === 2" v-permission="['student']">退选</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {cancelSelect, getSelectionList} from "@/api/selection";
import List from "@/mixins/list";
import YearSemesterShow from "@/components/YearSemesterShow/YearSemesterShow";

export default {
  components: {YearSemesterShow},
  data() {
    return {
      queryListFun: getSelectionList,
      name: '专业',
      deptList: []
    }
  },
  mixins: [
    List
  ],
  methods: {
    onClickCancel(courseId) {
      cancelSelect(courseId).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
        this.loadData({
          page: this.page,
          pageSize: this.pageSize
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
